using System.Text;

namespace ODX.Core
{
    internal static class FilterParser
    {
        internal delegate string Parameter(int n);
        internal static string Parse(string source, Parameter prm)
        {
            bool str = false;
            char ap = "'"[0];
            int n = 0;
            StringBuilder sb = new StringBuilder();

            foreach (char c in source)
            {
                if (c == ap)
                    str = !str;
                if (str || c != '?')
                {
                    sb.Append(c);
                    continue;
                }

                sb.Append(prm(n++));
            }
            return sb.ToString();
        }
    }
}
